<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
if( file_exists('stop.php') ) {
	include_once('stop.php');
}

//
require(dirname(dirname(__FILE__)) . '/includes/application_top.php');

//
function _link($link) {
	$link = stripslashes($link);
	//$link = trim(ereg_replace("[^A-Za-z0-9:#=_\!\@\%\$\^\&]", " ", $link));
	$link = trim(ereg_replace("[^A-Za-z0-9:#=_\!\@]", " ", $link));
	$link = trim(ereg_replace("( {1,})", " ", $link));
	$link = ereg_replace(" ", "_", $link);
	
	return $link;
}

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/menu/menu.class.php');
$mObj = new MenuBase();
$mObj->format = true;
$mObj->owner = '2';

//
$adb->query("delete from `pp_menus` where menus_owner = '2'");

//
$items = array(
		'A' => array(
				'name' => 'ECE Introduction',
				'link' => 'ECE-Introduction',
				'subs' => array(
						'1' => 'Brief Intro',
						'2' => 'Origin',
						'3' => 'Purpose',
						'4' => 'Vision and Mission',
						'5' => 'Moving beyond the typical',
						'6' => 'Making a difference',
						'7' => 'Key Services',
						'8' => 'Key Managers',
						'9' => 'Professional Team',
							),
					),
		'B' => array(
				'name' => 'Services',
				'link' => 'Services',
				'subs' => array(
						'1' => 'Services In TW',
						'2' => 'Services in US',
						'3' => 'Packages',
						'4' => 'Service Flow',
						'5' => 'Emergency Response',
						'6' => 'Procedure of CERT',
						'7' => 'Structure of CERT',
						'8' => 'Refund Policy',
							),
					),
		'C' => array(
				'name' => 'American Encyclopedia',
				'link' => 'American-Encyclopedia',
				'subs' => array(
						'1' => 'United States',
						'2' => '50 States',
						'3' => 'Major cities',
						'4' => 'Education System',
						'5' => 'Diagram',
							),
					),
		'D' => array(
				'name' => 'Visa and School',
				'link' => 'Visa-School',
				'subs' => array(
						'1' => 'Non-immigrant visa',
						'2' => 'Readiness for school time',
						'3' => 'Visa Status',
						'4' => 'Application to School',
						'5' => 'Application for non-immigrant visa',
						'6' => 'American Institute in Taiwan',
							),
					),
		'E' => array(
				'name' => 'ECE Information',
				'link' => 'Information',
				'subs' => array(
						'1' => 'Checklist',
						'2' => 'Leaving/Entering USA',
						'3' => 'Bank Information',
						'4' => 'Health and Insurance',
						'5' => 'FDA',
						'6' => 'FDA Charts',
						'7' => 'Test and Application',
							),
					),
		'F' => array(
				'name' => 'ECE Members',
				'link' => 'ECE-Members',
				'subs' => array(
						'1' => 'ECE Standard of Conduct Policies',
						'2' => 'CERT Agreement',
						'3' => 'ECE Services Contracts',
						'4' => 'Emergency Card',
							),
					),
		'G' => array(
				'name' => 'Contact ECE',
				'link' => 'Contact-ECE',
				'subs' => array(
						'1' => 'Company Info.',
							),
					),
			);							


//
$i = 0;
foreach($items as $key => $item) {
	$i++;
	$d = array();
	$d['_name'] = $item['name'];
	$d['_link'] = $item['link'];
	$d['_sort_order'] = $i;
	
	$items[$key]['id'] = $mObj->addItem($d);
}

//
foreach($items as $key => $item) {
	if( is_array($item['subs']) ) {
		$i = 0;
		foreach($item['subs'] as $k => $v) {
			$i++;
			$d = array();
			$d['_name'] = $v;
			$d['_link'] = $item['link'] . '-' . _link($v);
			$d['_parent'] = $item['id'];
			$d['_sort_order'] = $i;
			
			$mObj->addItem($d);
		}
	}
}

//
echo 'OK';
//
?>